#pragma once

#include "ColligereCddbDiscId.hpp"
#include "ColligereAudioDatabaseHandler.hpp"

namespace col
{

class SearchFreeDb
{
public:
	SearchFreeDb() { }
	SearchFreeDb ( const wxString &rDevice );

	class SearchResult
	{
	public:
		SearchResult();
		SearchResult ( const wxString &rCat, const wxString &rDiscId,
			const wxString &rTitle );

		const wxString &GetCategory() const;
		const wxString &GetDiscId() const;
		const wxString &GetTitle() const;
	private:
		wxString mCat, mDiscId, mTitle;
	};

	void SetDevice ( const wxString &rDevice );

	typedef std::deque < SearchResult > SearchResultDeque;

	SearchResultDeque Search();

	Artist DownloadResult ( const SearchResult &rResult );
private:
	const wxString DiscInfoToQuery();
	long ParseSearchResults ( const wxString &rFromData, SearchResultDeque &rTo );

	long GetServerResponseCode ( const wxString &rFromData ) const;

	SearchResult BuildSearchResultFromRegexMatch ( const wxRegEx &rRe, 
		const wxString &rData );

	const wxString GetServerHello() const;
	const wxString GetServerAddress() const;

	Artist ParseDatabaseItem ( const wxString &rFromData );

	CddbDiscId mDiscId;
};

}